package com.gccloud.dataroom.core.module.device.controller;

import com.gccloud.common.permission.ApiPermission;
import com.gccloud.common.utils.BeanConvertUtils;
import com.gccloud.common.vo.PageVO;
import com.gccloud.common.vo.R;
import com.gccloud.dataroom.core.module.device.dto.DataRoomDeviceDTO;
import com.gccloud.dataroom.core.module.device.dto.DeviceSearchDTO;
import com.gccloud.dataroom.core.module.device.entity.DataRoomDeviceEntity;
import com.gccloud.dataroom.core.module.device.service.IDataRoomDeviceService;
import com.gccloud.dataroom.core.module.device.vo.DataRoomDeviceVO;
import com.gccloud.dataroom.core.permission.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hongyang
 * @version 1.0
 * @date 2023/3/13 10:55
 */
@Slf4j
@RestController
@RequestMapping("/bigScreen/device")
@Api(tags = "大屏页以及大屏组件设计")
public class DataRoomDeviceController {

    @Resource
    private IDataRoomDeviceService dataRoomMapService;

    @ApiPermission(permissions = {Permission.Map.VIEW})
    @GetMapping("/page")
    @ApiOperation(value = "列表", position = 10, notes = "地图数据列表查询", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<PageVO<DataRoomDeviceEntity>> page(DeviceSearchDTO searchDTO) {
        PageVO<DataRoomDeviceEntity> page = dataRoomMapService.getPage(searchDTO);
        return R.success(page);
    }

    @ApiPermission(permissions = {Permission.Map.VIEW})
    @GetMapping("/list")
    @ApiOperation(value = "列表", position = 10, notes = "地图数据列表查询", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<List<DataRoomDeviceVO>> list(DataRoomDeviceDTO searchDTO) {
        List<DataRoomDeviceVO> list = dataRoomMapService.getList(searchDTO);
        return R.success(list);
    }

    @ApiPermission(permissions = {Permission.Map.ADD})
    @PostMapping("/add")
    @ApiOperation(value = "添加", position = 20, notes = "添加地图数据", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<String> add(@RequestBody DataRoomDeviceDTO mapDTO) {
        String id = dataRoomMapService.add(mapDTO);
        return R.success(id);
    }

    @ApiPermission(permissions = {Permission.Map.UPDATE})
    @PostMapping("/update")
    @ApiOperation(value = "修改", position = 30, notes = "修改地图数据", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<Void> update(@RequestBody DataRoomDeviceDTO mapDTO) {
        dataRoomMapService.update(mapDTO);
        return R.success();
    }

    @ApiPermission(permissions = {Permission.Map.DELETE})
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除", position = 40, notes = "删除地图数据", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<Boolean> delete(@PathVariable String id) {
        boolean delete = dataRoomMapService.delete(id);
        return R.success(delete);
    }


    @ApiPermission(permissions = {Permission.Map.VIEW})
    @GetMapping("/info/{id}")
    @ApiOperation(value = "详情", position = 70, notes = "地图数据详情", produces = MediaType.APPLICATION_JSON_VALUE)
    public R<DataRoomDeviceVO> info(@PathVariable String id) {
        DataRoomDeviceEntity info = dataRoomMapService.info(id);
        DataRoomDeviceVO vo = BeanConvertUtils.convert(info, DataRoomDeviceVO.class);
        return R.success(vo);
    }

}
